﻿<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport"
	content="width=device-width,initial-scale=1.0 user-scalable=yes">
<link href="css/jquery.mobile-1.2.0.min.css" rel="stylesheet"
	type="text/css" />
<link href="css/common.css" rel="stylesheet" />
<script src="js/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="js/jquery.mobile-1.2.0.min.js" type="text/javascript"></script>
<script src="js/phonegap.js"></script>
<script src="js/ChildBrowser.js"></script>
<script src="js/Oup.Http.URL.js"></script>
<script src="js/config.js"></script>
<script src="js/cookie.js"></script>
</head>
<body>
	<div data-role="page" id="rq_ProductDetail">
		<style type="text/css">
#title {
	text-align: center;
	color: #006699;
	font-weight: bold;
	font-size: 16px;
	background-color: #CCCCCC;
	margin-top: 5px;
	padding: 12px;
}
</style>
		<div data-theme="b" data-role="header" class="ui-header ui-bar-a"
			role="banner" data-position="fixed"
			style="position: fixed; border-width: 0px 0px 1px;">
			<h1 class="ui-title" role="heading" aria-level="1"></h1>
			<a id="btnback" href="#" data-role="button"
				data-inline="true" data-mini="true" data-theme="b">返回</a>
		</div>
		<div data-role="content">
			<input type="hidden" id="proId" />
			<div style="text-align: center;">
				<img alt="" title="" id="img1" src="#">
			</div>
			<div id="title"></div>
			<div id="contxt"
				style="font-size: 12px; margin-top: 5px; line-height: 20px; color: gray;">
			</div>
			<ul data-role="listview" data-divider-theme="b" data-inset="true"
				id="rq_PriceList">
			</ul>
		</div>
		<div data-role="footer" class="ui-footer ui-bar-a" role="contentinfo"
			data-position="fixed"
			style="position: fixed; border-width: 0px 0px 1px;">
			<div data-role="navbar" data-iconpos="top">
				<ul>
					<li><a id="btnfav" href="#" data-theme="b" data-icon="headerbtn4">喜欢 </a> <a
						style="display: none;" id="login" href="logindialog.html"
						data-theme="b" data-icon="" data-rel="dialog"
						data-transition="pop"></a></li>
					<li><a id="btnsharedialog" href="#" data-theme="b" data-icon="headerbtn5">分享 </a></li>
				</ul>
			</div>
		</div>

		<script type="text/javascript">
			//$(document).bind("mobileinit", function () {
			//    alert(1);
			//    $.mobile.autoInitialize = false; //删除这行配置参数就会出现渲染错误
			//});

			//$('#main').live("pageinit", function () {
			//    $.mobile.autoInitialize = false;
			//    $(document).bind("mobileinit", function () {
			//        //删除这行配置参数就会出现渲染错误
			//    });
			//});

			var urlContent = window.HtmlContent.getContent();
			var isFirst = true;
			//var id = Oup.Http.URL.getQueryString('id');
			var id= Oup.Http.URL.getString(urlContent,'id');
			
			GetDate(id);
			$(window).bind("hashchange", function(e) {
				if (isFirst) {
					isFirst = false;
					var id = Oup.Http.URL.getQueryString('id');
					GetDate(id);
				}
			});

			$(function() {
				$("#btnfav").click(function() {
					$("#btnfav").removeClass("ui-btn-active");
					if(typeof(window.HtmlContent)!="undefined" && typeof(window.HtmlContent.getUserId)!="undefined" && window.HtmlContent.getUserId()>0) {
						setFav();
					} else {
						location.href="?checklogin=1";
					}
				});
				$("#btnsharedialog").click(function(){
					$("#btnsharedialog").removeClass("ui-btn-active");
					location.href="sharedialog.html?id="+id+"&title="+$("#title").html();
				});
				$("a[name='proPriceList']").live("click", function() {
					var url = $(this).attr("val");
					//PhoneGap.exec("ChildBrowserCommand.showWebPage", url);
					location.href=url;
				});
				$("#btnback").click(function(){
					location.href="?goback=1";
				});
			});

			function GetDate(id) {
				if (id > 0) {
					$
							.ajax({
								type : "get",
								async : false,
								url : apihost + "/product/view",
								dataType : "json",
								data : {
									id : id
								},
								jsonp : "data",//服务端用于接收callback调用的function名的参数
								jsonpCallback : "success_jsonpCallback",//callback的function名称
								success : function(data) {
									var product = data.data;
									var priceList = data.data.compare_price;
									$("#img1").attr("src", product.img_url)
											.attr("alt", product.title).attr(
													"title", product.title);
									$("#title").html(product.title);
									$("#contxt").html(product.intro);
									$("#proId").val(id);
									var priceStr = "";
									$(priceList)
											.each(
													function() {
														priceStr += "<li data-theme=\"c\"><a name=\"proPriceList\" val=\"" + this.url + "\" target=\"_blank\" data-ajax=\"false\" href=\"#\" data-transition=\"slide\">"
																+ this.shop_name
																+ "<span class=\"ui-li-count\">￥"
																+ this.price
																+ "</span></a></li>";
														//priceStr += "<li data-theme=\"c\"><a val=\"" + this.url + "\" name=\"price\" data-ajax=\"false\" data-transition=\"slide\">" + this.shop_name + "<span class=\"ui-li-count\">￥" + this.price + "</span></a></li>";
													});
									$("#rq_PriceList").html(priceStr);
									if (priceStr != "") {
										try {
											$("#rq_PriceList").listview(
													'refresh');
										} catch (e) {
										}
									}
								},
								error : function() {
									//alert('fail');
								}
							});
				}
			}

			var GB2312UnicodeConverter = {
		            ToUnicode: function (str) {
		                return escape(str).toLocaleLowerCase().replace(/%u/gi, '\\u');
		            }
		            , ToGB2312: function (str) {
		                return unescape(str.replace(/\\u/gi, '%u'));
		            }
		        };
			
			function UnicodeToUTF8(strInUni){
				  if(null==strInUni)
				    returnnull;
				  var strUni=String(strInUni);
				  var strUTF8=String();
				  for(var i=0;i<strUni.length;i++){
				    var wchr=strUni.charCodeAt(i);
				    if(wchr<0x80){
				      strUTF8+=strUni.charAt(i);
				      }
				    else if(wchr<0x800){
				      var chr1=wchr&0xff;
				      var chr2=(wchr>>8)&0xff;
				      strUTF8+=String.fromCharCode(0xC0|(chr2<<2)|((chr1>>6)&0x3));
				      strUTF8+=String.fromCharCode(0x80|(chr1&0x3F));
				      }
				    else{
				      var chr1=wchr&0xff;
				      var chr2=(wchr>>8)&0xff;
				      strUTF8+=String.fromCharCode(0xE0|(chr2>>4));
				      strUTF8+=String.fromCharCode(0x80|((chr2<<2)&0x3C)|((chr1>>6)&0x3));
				      strUTF8+=String.fromCharCode(0x80|(chr1&0x3F));
				      }
				    }
				  return strUTF8;
				  }
			
			function setFav() {
				$.ajax({
					type : "post",
					async : false,
					url : apihost + "/like/product",
					dataType : "json",
					data : {
						uid : window.HtmlContent.getUserId(),
						pid : $("#proId").val(),
						type : "fav"
					},
					jsonp : "data",//服务端用于接收callback调用的function名的参数
					jsonpCallback : "success_jsonpCallback",//callback的function名称
					success : function(json) {
						//alert(json.msg);
						//document.write(json.msg);
						location.href="?alert="+json.msg;
					},
					error : function() {
						//alert('fail');
					}
				});
			}
		</script>
	</div>
</body>
</html>
